#include <iostream>
using namespace std;

class Array
{
	private :
		int *m_p;
		size_t m_len;

	public :
		Array(size_t n = 0);
		~Array();
		Array(const Array& a);
		Array& operator=(const Array& a);

		int& operator[](size_t index)
		{
			static int i = -1;

			cout << "<Operator[]>" << endl;

			if(index < m_len)
			{
				return m_p[index];
			}
			else
			{
				cout << "Out of range" << endl;
				return i;
			}
		}

		const int& operator[](size_t index) const
		{
			static int i = -1;

			cout << "<Operator[] const>" << endl;

			if(index < m_len)
			{
				return m_p[index];
			}
			else 
			{
				cout << "Out of range" << endl;
				return i;
			}
		}
	protected :
};

Array :: Array(size_t n)
{
	m_len = n;
	m_p = new int[m_len];
	*m_p = 0;
}

Array :: ~Array()
{
	delete [] m_p;
}

Array :: Array(const Array& a)
{
	m_len = a.m_len;
	m_p = a.m_p;
}

Array& Array :: operator=(const Array& a)
{
	if(this != &a)
	{
		delete [] m_p;
		m_len = a.m_len;
		m_p = new int[m_len];
		m_p = a.m_p;
	}

	return *this;
}

size_t func(const Array& a)
{
	size_t i = a[7];
	return i;
}

int main()
{
	Array a1(10);

	cout << "a1[4] = " << a1[4] << endl << endl;
	cout << "a1[11] = " << a1[11] << endl << endl;

	a1[0] = 1;
	cout << "a1[0] = " << a1[0] << endl << endl;

	cout << "func() : " << func(a1) << endl << endl;
}
